package com.tc.shiro.controller;

import com.tc.shiro.model.OperatorInfo;
import com.tc.shiro.model.QueryRoleRespModel;
import com.tc.shiro.constants.MerchantWebappConstants;
import com.tc.shiro.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/shiro")
public class RoleController extends AbstractController {
    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/queryRoleDetail", method = RequestMethod.GET)
    @RequiresPermissions("authMng:queryRole")
    public ResponseEntity<QueryRoleRespModel> queryRoleDetail(HttpServletRequest request, String roleNo) {
        log.info("入参roleNo:{}",roleNo);
        OperatorInfo operatorInfo = (OperatorInfo) request.getSession()
                .getAttribute(MerchantWebappConstants.OPERATOR_INFO_SESSION_NAME);
        String mercNo = operatorInfo == null ? null : operatorInfo.getMercNo(); // 从session中获取商户ID
        String requestId = UUID.randomUUID().toString();
        QueryRoleRespModel respModel = roleService.queryRole(requestId, mercNo, roleNo);
        return new ResponseEntity<>(respModel, HttpStatus.OK);
    }

}
